import Vue from 'vue'
import App from './App.vue'
import router from './router'

import axios from 'axios'
//设置默认的 api 域名基准路径
axios.defaults.baseURL = 'http://liangwei.tech:3000'
// 绑定到原型
Vue.prototype.$axios = axios


//添加拦截器，放入token
axios.interceptors.request.use(config =>{
  if(!config.headers.Authorization && localStorage.getItem('token')){
    config.headers.Authorization = localStorage.getItem('token')
  }
  return config
})

//引入ElementUI
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

Vue.use(ElementUI)

 // 补齐图片地址
Vue.filter('fixImgUrl',(oldUrl)=>{
  if (oldUrl.indexOf('http')>-1) {
    return oldUrl
  }else{
    return axios.defaults.baseURL + oldUrl
  }

})

Vue.config.productionTip = false

new Vue({
  router,
  render: function (h) { return h(App) }
}).$mount('#app')
